<template>
	<view class="container">
		<scroll-view scroll-y="true" @scrolltolower="lower" style="height: 100vh;">
			<view class="wid100 bacFFF mar-bott30" v-for="(item,index) in list" :key="index"
				style="padding: 30rpx 0;" @click="tiaozhuan('/pages/user/exchangeDetails?id='+item.id)">
				<view class="wid90 mar">
					<view class="foSi25 dis disAl disJuB">
						<view>兑换单号：{{item.order_id}}</view>
						<view class="" v-if="item.pay_status == 1">
							<view v-if="item.status === 1">待发货</view>
							<view v-if="item.status === 2" style="color: #FF0000;">已发货</view>
							<view v-if="item.status === 3">已收货</view>
						</view>
						<view class="" v-if="item.pay_status == 0">
							<view style="color: red;">待支付</view>
						</view>
						<view class="" v-if="item.pay_status == 2">
							<view style="color: red;">已退款</view>
						</view>
					</view>
					<view class="mar-top30 dis disAl">
						<view class="wid20">
							<image :src="item.cover_img" 
								style="width: 108rpx;height: 108rpx;"></image>
						</view>
						<view class="wid80">
							<view class="wid100 foSi30 fowebl overflowHidden">{{item.title}}</view>
							<view class="foSi25 mar-top10" style="color: #5B5B5B;">x{{item.num}}</view>
							<view class="mar-top10 dis disAl disJuB">
								<view class="foSi18" style="color: #5B5B5B;">兑换日期：{{item.createtime}}</view>
								<view class="foSi25" style="color: #FF0000;" v-if="item.pay_type == 1">{{item.pay_integral}}积分</view>
								<view class="foSi25" style="color: #FF0000;" v-if="item.pay_type == 2">{{item.pay_money}}元</view>
								<view class="foSi25" style="color: #FF0000;" v-if="item.pay_type == 3">{{parseFloat(parseFloat(item.pay_money) + parseFloat(item.pay_weixin)) }}元</view>
							</view>
						</view>
					</view>
					<view class="dis disAl mar-top40" style="justify-content: flex-end;">
						<view v-if="item.status == 2" class="dis disAl disJuC foSi22 borRad40 bott bottCor mar-left30" @click="qrsh(item.id)">确认收货</view>
					</view>
				</view>
			</view>
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/imgs/icon/zanwu1.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<view class="hei20"></view>
		</scroll-view>
	</view>
</template>

<script>
	import { Goods } from '../../model/integralgoods-model';
	var Goods2 = new Goods()
	import { Config } from '../../utils/config.js';
	export default {
		data() {
			return {
				url: Config.restUrl,
				last_page: 0,
				page: 1,
				list: []
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(e) {
			this.getList()
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			this.page = 1
			
			this.getList()
		},
		methods: {
			getList(){
				var that = this
				let params = {
					page: that.page
				}
				Goods2.goodsRecord((data) => {
					console.log(data)
					if (data.code === 0) {
						that.last_page = data.data.last_page
						that.list = that.page === 1?data.data.data:that.list.concat(data.data.data)
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
					uni.hideNavigationBarLoading(); //完成停止加载
					uni.stopPullDownRefresh();
				}, params)
			},
			qrsh(id){
				
				var that = this
				let params = {
					id: id
				}
				Goods2.confirm_receipt((data) => {
					console.log(data)
					if (data.code === 0) {
						that.page = 1
						that.getList()
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
					uni.hideNavigationBarLoading(); //完成停止加载
					uni.stopPullDownRefresh();
				}, params)
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				});
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
		}
	};
</script>
<style>
	.container {
		height: 100vh;
		background-color: #F7F7F7;
	}
	.bott{
		width: 140rpx;
		height: 50rpx;
		border: 2rpx solid #646666;
		color: #646666;
	}
	.bottCor{
		border-color: #FF0000;
		color: #FF0000;
	}
</style>